package com.fresh.wx.utils;


import java.util.List;

import net.sf.json.JSONObject;

/**
 * w
 * @author admin
 *
 */
public class WXMsgTemplete implements Runnable {
	
	private List<String> list;
	private String title;
	private String sendDate;
	private String  pack;
	
	/**
	 * 异步发送微信模板
	 * @param list   openId
	 * @param title  标题 
	 * @param sendDate  到货日期
	 * @param pack     包装内容
	 */
	public  WXMsgTemplete(List<String> list, String title,String sendDate,String  pack){
	       this.list = list;
		   this.title = title;
		   this.sendDate = sendDate;
		   this.pack = pack;
	}

	/**
	 * 发送微信模板消息
	 * @param openId
	 * @param title
	 * @param sendDate
	 * @param pack
	 */
	public static void sendTmp( String openId,String title,String sendDate,String  pack){
		
		String URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+WXConfig.TOKEN;
		
		String json ="{";
		json+=   "\"touser\":\""+openId+"\",";
		json+=   "\"template_id\":\"SrbmJ-fv1Wn2tW_I3ZZjcoDZV4U0nWPu11Uc7KRyKaw\",";
		json+=   "\"url\":\"http://zx.leadfresh.cn/fresh-cloud-api/seller/index\",";  
		json+=   "\"data\":{";
		json+=    "\"first\": {";
		json+=                     "\"value\":\""+title+"！\",";
		json+=                     "\"color\":\"#173177\"";
		json+=                  "},";
		json+=     "\"keyword1\":{";
		json+=                   "\"value\":\""+pack+"\",";
		json+=                   "\"color\":\"#173177\"";
		json+=                   "},";
		json+=       "\"keyword2\": {";
		json+=                 "\"value\":\""+sendDate+"\",";
		json+=                 "\"color\":\"#173177\"";
		json+=             "},";
        json+=      "\"remark\":{";
        json+=                 "\"value\":\"请及时到卖家中心查看订单（超过30分钟订单将回收到系统。）！\",";
        json+=                  "\"color\":\"#173177\"";
        json+=           "}";
        json+=      "}";
        json+=  "}";
		
        System.out.println(json);
		
		JSONObject jsonObject = CommonUtil.httpsRequest(URL, "POST", json);
		System.out.println("jsonObject    : "+jsonObject);
		
	}
	
	@Override
	public void run() {
		// TODO Auto-generated method stub
	
		//发送微信模板推送 
		if(list!=null){
			for (int i = 0; i < list.size(); i++) {
				sendTmp(list.get(i), title, sendDate, pack);
			}
		}
	}
	
}
